package com.xu.microservice.controller;

import com.xu.microservice.MemberService;
import com.xu.microservice.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/microservice")
@EnableAutoConfiguration
public class MyController {

    @Autowired
    private MemberService service;

    @RequestMapping("/hello")
    @ResponseBody
    public String hello() {
        /*List<Member> members = service.findByExample();
        for (Member member : members) {
            System.out.println(member.getId());
        }*/
        service.insert1("test5");
        return "hello springboot 2.8";
    }

    @RequestMapping("/members")
    public String findAll(Model model) {
        List<Member> members = service.findAll();
        model.addAttribute("members", members);
        return "theyeleaf";
    }
}
